<?PHP	//header
include('config/config.php');
include('php/header.php');
require "php/functions.php";
?>        

<?PHP	//Connect to database
	$conn = mysql_connect($cfg["connection"]["host"], $cfg["connection"]["userName"], $cfg["connection"]["password"]) 
		or die ('Error Cannot Connect to MySQL');
	@mysql_select_db($cfg["connection"]["database"]) or die( "Unable to select database");
?>
    <h2>Global Detailed Orders</h2> 
<?PHP	//pagination; for displaying main window's contain
		
		$tbl_name=$cfg["tbl"]["inventory"];	//your table name
		/* Setup vars for query. */
		// How many adjacent pages should be shown on each side?
		$adjacents = 3;
		$targetpage = "manage_ordersFromShop.php"; 			//your file name  (the name of this file)
		$limit = 15; 						//how many items to show per page
		if (isset($_GET['page'])) $page = $_GET['page'];
		else $page = 1;
		if ($page) $start = ($page - 1) * $limit; 			//first item to display on this page
		else $start = 0;									//if no page var is given, set start to 0
		
		/* Get data. */
		$sql = "SELECT i.itemId, i.itemName, i.category, t.shopId, t.tDate, t.unit_sold
				FROM item i INNER JOIN local_transaction t 
				ON i.itemId = t.itemId
				ORDER BY t.shopId ASC";
		$result = mysql_query($sql);
		/* 
		   First get total number of rows in data table. 
		   If you have a WHERE clause in your query, make sure you mirror it here.
		*/
		$total_items = mysql_num_rows($result);
		$sql = "SELECT i.itemId, i.itemName, i.category, t.shopId, t.tDate, t.unit_sold
				FROM item i INNER JOIN local_transaction t 
				ON i.itemId = t.itemId
				ORDER BY t.shopId ASC
				LIMIT $start, $limit";
		$result = mysql_query($sql);
		include('config/pagination.php');
?>
                    
<table id="rounded-corner" summary="Inventory Database">
    <thead>
    	<tr>
			<th scope="col" class="rounded-company"></th>
			<th scope="col" class="rounded">Shop ID</th>
            <th scope="col" class="rounded">Barcode</th>
            <th scope="col" class="rounded">Product Name</th>
            <th scope="col" class="rounded">Category</th>
            <th scope="col" class="rounded">Transaction Date</th>
            <th scope="col" class="rounded-q4">Unit Sold</th>
        </tr>
    </thead>
        <tfoot>
    	<tr>
        	<td colspan="6" class="rounded-foot-left"><em>Join Tables</em></td>
        	<td class="rounded-foot-right">&nbsp;</td>

        </tr>
    </tfoot>
	
    <tbody>
	<?PHP	//output from database to main window's box
	echo '<div class="divOuter">';		//parent div ----- just to format multiple children divs inline
		
			while($row = mysql_fetch_array($result)){
				echo "<tr>";
					echo "<td></td>";
					echo "<td>".$row[$cfg["tbl_transaction"]['shopID']]."</td>";
					echo "<td>".$row[$cfg["tbl_inventory"]["barcode"]]."</td>";
					echo "<td>".$row[$cfg["tbl_inventory"]["product_name"]]."</td>";
					echo "<td>".$row[$cfg["tbl_inventory"]['category']]."</td>";
					echo "<td>".$row[$cfg["tbl_transaction"]['transaction_date']]."</td>";
					echo "<td>".$row[$cfg["tbl_transaction"]['unit_sold']]."</td>";
				echo "</tr>";
			}
	echo '</div>';
	?>
	</tbody>
</table>

	<?PHP
	if (isset($_POST['action'])) {
		if (($_POST['action'] == "View items from category") && (isset($_POST['checkbox_Inventory']))) {
		//List all product in the same category with THE 1st CHECKED-BOX item
			session_start();
			$_SESSION['checkbox_Inventory'] = $_POST['checkbox_Inventory'];
			header("Location: category.php");
		}
		elseif ($_POST['action'] == "Add new item") {
			header("Location: add_inventory.php");
		}
		elseif ($_POST['action'] == "Delete items") {
			if (isset($_POST['checkbox_Inventory'])) {
				session_start();
				$_SESSION['checkbox_Inventory'] = $_POST['checkbox_Inventory'];
				header("Location: delete_inventory.php");
			}
		}
	}
	?>	
     
	<div class="pagination">
	<?PHP	
		echo $pagination
	?>
<?PHP	//footer
include('php/footer.php');
?>